package com.jinkeen.xiaxie.recycleview

import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.jinkeen.xiaxie.R
import com.jinkeen.xiaxie.databinding.ItemMyRecycleviewBinding

/**
 * @description: TODO
 * @author whz
 * @date 2021/9/17 16:39
 * @version 1.0
 */

class MyRvAdapter : RecyclerView.Adapter<MyRvAdapter.MyViewHolder> {

    private lateinit var userList: ArrayList<User>
    private var context: Context? = null

    @SuppressLint("NotifyDataSetChanged")
    constructor(usetList: ArrayList<User>, context: Context) {
        this.context = context
        notifyDataSetChanged()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
        return MyViewHolder(
            LayoutInflater.from(context).inflate(R.layout.item_my_recycleview, parent, false)
        )
    }

    override fun getItemCount(): Int = userList.size

    override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
        holder.binding.tvName.text = userList[position].name
        holder.binding.tvPhone.text = userList[position].phone
        holder.binding.tvSex.text = userList[position].sex
    }


    class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val binding: ItemMyRecycleviewBinding = ItemMyRecycleviewBinding.bind(itemView)
    }
}

